<?php

//header('Access-Control-Allow-Origin: http://www.baidu.com');
//header('Access-Control-Allow-Headers: X-Requested-With,X_Requested_With');
date_default_timezone_set("Asia/chongqing");
error_reporting(E_ERROR);
header("Content-Type: text/html; charset=gbk");

require '../../../../../source/class/class_core.php';
$discuz = C::app();

$cachelist = array('plugin');
$discuz->cachelist = $cachelist;
$discuz->init();

$var = dunserialize($_G['setting']['dzapp_base']);

$CONFIG = json_decode(preg_replace("/\/\*[\s\S]+?\*\//", "", file_get_contents("config.json")), true);
$action = $_GET['action'];

switch ($action) {
    case 'config':
        $result =  json_encode($CONFIG);
        break;

    case 'uploadimage':

    case 'uploadscrawl':

    case 'uploadvideo':

    case 'uploadfile':
        $result = include("action_upload.php");
        break;

    case 'listimage':
        $result = include("action_list.php");
        break;
    case 'listfile':
        $result = include("action_list.php");
        break;

    case 'catchimage':
        $result = include("action_crawler.php");
        break;

    default:
        $result = json_encode(array(
            'state'=> lang('plugin/dzapp_base', 'state_1')
        ));
        break;
}


if (isset($_GET["callback"])) {
    if (preg_match("/^[\w_]+$/", $_GET["callback"])) {
        echo htmlspecialchars($_GET["callback"]) . '(' . $result . ')';
    } else {
        echo json_encode(array(
            'state'=> lang('plugin/dzapp_base', 'state_2')
        ));
    }
} else {
    echo $result;
}